package com.jiawa.train.business.controller.admin;

import com.jiawa.train.business.req.TrainQueryReq;
import com.jiawa.train.business.req.TrainSaveReq;
import com.jiawa.train.business.service.TrainSeatService;
import com.jiawa.train.business.service.TrainService;
import com.jiawa.train.common.resp.PageResult;
import com.jiawa.train.common.resp.Result;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/train")
@Slf4j
public class TrainAdminController {

    @Resource
    private TrainService trainService;

    @Resource
    private TrainSeatService trainSeatService;
    @PostMapping("/save")
    public Result save(@RequestBody @Valid TrainSaveReq req) {
        trainService.save(req);
        return Result.success();
    }
    @GetMapping("/page")
    public Result<PageResult> queryTrainList(TrainQueryReq  req) {
       PageResult pageResult = trainService.queryTrainList(req);
       return Result.success(pageResult);
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        trainService.delete(id);
        return Result.success();
    }

    @GetMapping("/query-all")
    public Result queryAll(){
        List trainList = trainService.queryAll();
        return Result.success(trainList);
    }
    @GetMapping("/gen-seat/{trainCode}")
    public Result genSeat(@PathVariable String trainCode){
        trainSeatService.genSeat(trainCode);
        return Result.success();
    }

}

